package com.stylefeng.guns.modular.bus.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.CompanyInfo;
import com.stylefeng.guns.modular.bus.service.ICompanyInfoService;

/**
 * company控制器
 *
 * @author fengshuonan
 * @Date 2018-04-19 12:14:13
 */
@Controller
@RequestMapping("/companyInfo")
public class CompanyInfoController extends BaseController {

    private String PREFIX = "/bus/companyInfo/";

    @Autowired
    private ICompanyInfoService companyInfoService;

    /**
     * 跳转到company首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "companyInfo.html";
    }

    /**
     * 跳转到添加company
     */
    @RequestMapping("/companyInfo_add")
    public String companyInfoAdd() {
        return PREFIX + "companyInfo_add.html";
    }

    /**
     * 跳转到修改company
     */
    @RequestMapping("/companyInfo_update/{companyInfoId}")
    public String companyInfoUpdate(@PathVariable Integer companyInfoId, Model model) {
        CompanyInfo companyInfo = companyInfoService.selectById(companyInfoId);
        model.addAttribute("item",companyInfo);
        LogObjectHolder.me().set(companyInfo);
        return PREFIX + "companyInfo_edit.html";
    }

    /**
     * 获取company列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return companyInfoService.selectList(null);
    }

    /**
     * 新增company
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(CompanyInfo companyInfo) {
        companyInfoService.insert(companyInfo);
        return SUCCESS_TIP;
    }

    /**
     * 删除company
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer companyInfoId) {
        companyInfoService.deleteById(companyInfoId);
        return SUCCESS_TIP;
    }

    /**
     * 修改company
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(CompanyInfo companyInfo) {
        companyInfoService.updateById(companyInfo);
        return SUCCESS_TIP;
    }

    /**
     * company详情
     */
    @RequestMapping(value = "/detail/{companyInfoId}")
    @ResponseBody
    public Object detail(@PathVariable("companyInfoId") Integer companyInfoId) {
        return companyInfoService.selectById(companyInfoId);
    }
}
